{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "3c8413a0",
   "metadata": {},
   "source": [
    "# 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "84b6c111",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "39"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import random\n",
    "wait_time = random.randint(1,60)\n",
    "wait_time"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "d592e24c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'bottles'"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "word = \"bottles\"\n",
    "word"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "99c23ae3",
   "metadata": {},
   "source": [
    "### 使用列表"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "b5952804",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "i\n",
      "i\n",
      "a\n"
     ]
    }
   ],
   "source": [
    "vowels = ['a','e','i','o','u']\n",
    "word = \"Milliways\"\n",
    "for letter in word:\n",
    "    if letter in vowels:\n",
    "        print(letter)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "19931cab",
   "metadata": {},
   "source": [
    "### 有多行代码时使用编辑器"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "a32eb6c4",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "i\n",
      "i\n",
      "a\n"
     ]
    }
   ],
   "source": [
    "vowels = ['a','e','i','o','u']\n",
    "word = \"Milliways\"\n",
    "for letter in word:\n",
    "    if letter in vowels:\n",
    "        print(letter)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "de332a86",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "found = []\n",
    "len(found)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "a38a80bb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "found.append('a')\n",
    "len(found)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "d14024cb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['a']"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "found"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "146b66d0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "found.append('a')\n",
    "found.append('i')\n",
    "found.append('o')\n",
    "len(found)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "8d796743",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['a', 'a', 'i', 'o']"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "found"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2c0a0ec6",
   "metadata": {},
   "source": [
    "### 用“in”检查成员关系"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "cd39027f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['a', 'a', 'i', 'o', 'u']"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "if 'u' not in found:\n",
    "    found.append('u')\n",
    "found"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "caf221e7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['a', 'a', 'i', 'o', 'u']"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "if 'u' not in found:\n",
    "    found.append('u')\n",
    "found"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "1897dce3",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['a', 'e', 'i', 'o', 'u']\n",
      "['a', 'e', 'i', 'o', 'u']\n"
     ]
    }
   ],
   "source": [
    "vowels = ['a','e','i','o','u']\n",
    "word = \"Milliways\"\n",
    "found = []\n",
    "for letter in word:\n",
    "    if letter in vowels:\n",
    "        if letter not in found:\n",
    "            found.append(letter)\n",
    "for vowel in found:\n",
    "    print(vowels)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "03d5efee",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Provide a word to search for vowels:python\n",
      "o\n"
     ]
    }
   ],
   "source": [
    "vowels = ['a','e','i','o','u']\n",
    "word = input(\"Provide a word to search for vowels:\")\n",
    "found = []\n",
    "for letter in word:\n",
    "    if letter in vowels:\n",
    "        if letter not in found:\n",
    "            found.append(letter)\n",
    "for vowel in found:\n",
    "    print(vowel)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4466e7da",
   "metadata": {},
   "source": [
    "# 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "id": "62a1a7b2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 2, 3, 4]"
      ]
     },
     "execution_count": 64,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nums = [1, 2, 3, 4]\n",
    "nums"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "id": "11f038a0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 2, 4]"
      ]
     },
     "execution_count": 65,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nums.remove(3)\n",
    "nums"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f7e144a7",
   "metadata": {},
   "source": [
    "### 从列表弹出对象"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "id": "db0946be",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4"
      ]
     },
     "execution_count": 66,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nums.pop()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "id": "0428730c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 2]"
      ]
     },
     "execution_count": 67,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nums"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "id": "f3df5de9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 68,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nums.pop(0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "id": "79eb6395",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 75,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nums"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "id": "390fbb49",
   "metadata": {},
   "outputs": [],
   "source": [
    "nums = [2]\n",
    "nums.extend([3, 4])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 80,
   "id": "6a4101f5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Don't panic!\n",
      "['D', 'o', 'n', \"'\", 't', ' ', 'p', 'a', 'n', 'i', 'c', '!']\n",
      "['o', 'n', ' ', 't', 'a', 'p']\n",
      "on tap\n"
     ]
    }
   ],
   "source": [
    "phrase = \"Don't panic!\"\n",
    "plist = list(phrase)\n",
    "print(phrase)\n",
    "print(plist)\n",
    "for i in range(4):\n",
    "    plist.pop()\n",
    "plist.pop(0)\n",
    "plist.remove(\"'\")\n",
    "plist.extend([plist.pop(),plist.pop()])\n",
    "plist.insert(2,plist.pop(3))\n",
    "new_phrase = ''.join(plist)\n",
    "print(plist)\n",
    "print(new_phrase)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3fc87ee1",
   "metadata": {},
   "source": [
    "# 3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "2a90d42d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Don't panic!\n",
      "['D', 'o', 'n', \"'\", 't', ' ', 'p', 'a', 'n', 'i', 'c', '!']\n",
      "['D', 'o', 'n', \"'\", 't', ' ', 'p', 'a', 'n', 'i', 'c', '!']\n",
      "on tap\n"
     ]
    }
   ],
   "source": [
    "phrase = \"Don't panic!\"\n",
    "plist = list(phrase)\n",
    "print(phrase)\n",
    "print(plist)\n",
    "new_phrase = ''.join(plist[1:3])\n",
    "new_phrase = new_phrase + ''.join([plist[5],plist[4],plist[7],plist[6]])\n",
    "print(plist)\n",
    "print(new_phrase)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6dfdeb0a",
   "metadata": {},
   "source": [
    "### 看起来像复制，但其实不是"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "id": "e0aec211",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 2, 3, 4, 5]"
      ]
     },
     "execution_count": 81,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "first = [1, 2, 3, 4, 5]\n",
    "first"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 82,
   "id": "d758e1a3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 2, 3, 4, 5]"
      ]
     },
     "execution_count": 82,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "second = first\n",
    "second"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "6fe16bfa",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\t M\n",
      "\t a\n",
      "\t r\n",
      "\t v\n",
      "\t i\n",
      "\t n\n"
     ]
    }
   ],
   "source": [
    "paranoid_android = \"Marvin\"\n",
    "letters = list(paranoid_android)\n",
    "for char in letters:\n",
    "    print('\\t',char)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "0be484d2",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\t M\n",
      "\t a\n",
      "\t r\n",
      "\t v\n",
      "\t i\n",
      "\t n\n",
      "\n",
      "\t\t A\n",
      "\t\t n\n",
      "\t\t d\n",
      "\t\t r\n",
      "\t\t o\n",
      "\t\t i\n",
      "\t\t d\n",
      "\n",
      "\t\t\t P\n",
      "\t\t\t a\n",
      "\t\t\t r\n",
      "\t\t\t a\n",
      "\t\t\t n\n",
      "\t\t\t i\n",
      "\t\t\t o\n",
      "\t\t\t d\n"
     ]
    }
   ],
   "source": [
    "paranoid_android = \"Marvin, the Paraniod Android\"\n",
    "letters = list(paranoid_android)\n",
    "for char in letters[:6]:\n",
    "    print('\\t',char)\n",
    "print()\n",
    "for char in letters[-7:]:\n",
    "    print('\\t'*2,char)\n",
    "print()\n",
    "for char in letters[12:20]:\n",
    "    print('\\t'*3,char)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "82bd0063",
   "metadata": {},
   "source": [
    "# 4.列表有什么问题"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "a7efbec4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Ford Perfect', 'Male', 'Researcher', 'Betelgeuse Seven']"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "personl = ['Ford Perfect','Male','Researcher','Betelgeuse Seven']\n",
    "personl"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "fec67d2c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Name',\n",
       " 'Huichun',\n",
       " 'Gender',\n",
       " 'Female',\n",
       " 'Occupation',\n",
       " 'Student',\n",
       " 'Home Planet',\n",
       " 'Guangdong Shantou']"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "person2 = ['Name','Huichun','Gender','Female','Occupation','Student','Home Planet','Guangdong Shantou']\n",
    "person2"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "73c708c5",
   "metadata": {},
   "source": [
    "# 5.购物车项目"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 85,
   "id": "0b8cdd92",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "------相机-------\n",
      "索尼6400 6600元\n",
      "富士xt4 15000元\n",
      "佳能850D 7000元\n",
      "请输入您的余额(退出时输入Q)：6700\n",
      "[['索尼6400', 6600], ['富士xt4', 15000], ['佳能850D', 7000]]\n",
      "\n",
      "请输入商品编号进行商品的购买:3\n",
      "商品总价是7000元\n",
      "余额不足，购买失败\n",
      "您购买的商品：['佳能850D', 7000]\n",
      "您还有-300元\n"
     ]
    }
   ],
   "source": [
    "goods_list = [[\"索尼6400\",6600],[\"富士xt4\",15000],[\"佳能850D\",7000]]\n",
    "shopping_list = [\"1\",\"2\",\"3\"]\n",
    "goodsprice = [6600,15000,7000]\n",
    "while True:\n",
    "    print(\"------相机-------\")\n",
    "    for i in range(3):\n",
    "        print(goods_list[i][0],str(goods_list[i][1])+\"元\")\n",
    "    balance = input(\"请输入您的余额\"'(退出时输入Q)：')\n",
    "    if balance == \"Q\":\n",
    "         break\n",
    "    print(f\"{goods_list}\\n\")\n",
    "    choose_goods = input(\"请输入商品编号进行商品的购买:\")\n",
    "    num = int( choose_goods)\n",
    "    goodschosen_price = goodsprice[num-1]\n",
    "    goodschosen_list = goods_list[num-1]\n",
    "    print(f\"商品总价是{goodschosen_price}\"+\"元\")\n",
    "    if int(balance) >= goodschosen_price:\n",
    "        print(\"购买成功\") \n",
    "    elif int(balance) < goodschosen_price:\n",
    "        print(\"余额不足，购买失败\")\n",
    "    balance = int(balance)\n",
    "    balance -= goodschosen_price\n",
    "    print(f\"您购买的商品：{goodschosen_list}\\n您还有{balance}\"+\"元\")\n",
    "    break"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "06e9784e",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
